var ctx;
function setCtx(ctx) {
    this.ctx = ctx;
}
var status = false;
function setPayStatus(status){
	this.status = status;
}
$(function(){
	
	$('.new-add').click(function() {
		var orderInfoId = $('#orderInfoId').val();
		var index = parent.layer.getFrameIndex(window.name);
		layer.open({
			title: false,
			type: 2,
			content: ctx + '/shopcart/addAddress',
			area: ["750px","500px"],
	      	btn: ['确定', '取消']
		    	,yes: function(index, layero){ //或者使用btn1
		        	//按钮【按钮一】的回调
		    		var iframeWin = window[layero.find('iframe')[0]['name']]; 
		    		iframeWin.saveAddress();
		    		layer.close(index);
		    	},cancel: function(index){ //或者使用btn2
		        	//按钮【按钮二】的回调
		    	},
				end: function(){
					location.href = ctx + "/orderInfo/payMoney?orderInfoId=" + orderInfoId;
				}
			});
	});
	
	$(".pay-btn").click(function() {
		var orderInfoId = $('#orderInfoId').val();
		$.ajax({
			type: "POST",
			url: ctx + "/orderInfo/comfirmPayMoney",
		   	data: {orderInfoId : orderInfoId},
		   	dataType:"json",
		   	contentType : 'application/json;charset=utf-8', //设置请求头信息
			success: function(data){
				layer.open({
					type: 2,
					title: '微信支付',
					content: ctx + "/views/mall/pay_complete.jsp?orderId=" + orderInfoId,
					skin: "house-add",
					area: ["505px","380px"],
					end: function(){
						if(!status){
							location.href = ctx + '/orderInfo/orderInfoListByState';
						}
					}
				});
			},
			error: function(res){
			}
		});

		
//		layer.open({
//			type: 2,
//			title: '微信支付',
//			content: ctx + "/shopcart/sumbitOrder?shopcartIds=" + shopcartId + "&orderInfo=" +users,
//			skin: "house-add",
//			area: ["505px","380px"],
//			end: function(){
//				if(!status){
//					location.href = ctx + '/shopcart/shopcartList';
//				}
//			}
//		});
	});
});

function selectCoupon(shopId) {
	layer.open({
		type: 2,
		title: '请选择优惠券',
		content: ctx + "/shopcart/sumbitOrder?shopcartIds=" + "",
		skin: "house-add",
		area: ["505px","380px"],
		end: function(){
			if(!status){
				location.href = ctx + '/shopcart/shopcartList';
			}
		}
	});
}

